﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QD.SQLHelper
{
    /// <summary>
    /// 数据库配置
    /// </summary>
    public sealed class DbConfig
    {
        private DbConfig() { }

        private static object sysObj = new object();
        private static DbConfig instance;

        public static DbConfig Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (sysObj)
                    {
                        if (instance == null)
                        {
                            instance = new DbConfig();
                        }
                    }
                }
                return instance;
            }
        }

        /// <summary>
        /// 登录用户
        /// </summary>
        public string Uid { get; set; }

        /// <summary>
        /// 登录用户密码
        /// </summary>
        public string PWD { get; set; }

        /// <summary>
        /// 应用编号
        /// </summary>
        public string QfCode { get; set; }

        /// <summary>
        /// 应用名称
        /// </summary>
        public string QfName { get; set; }

        /// <summary>
        /// 平台数据库名称
        /// </summary>
        public string DbDataBaseName { get; set; }

        /// <summary>
        /// 内部数据库
        /// </summary>
        public string DbResourcesName { get; set; }

        /// <summary>
        /// 主数据库名称
        /// </summary>
        public string DbMasterName { get; set; }

        /// <summary>
        /// 配置数据库名称
        /// </summary>
        public string DbConfigName { get; set; }

        private LogonConfig _LogonConfig;
        /// <summary>
        /// 数据库登录信息
        /// </summary>
        public LogonConfig LogonConfig
        {
            get
            {
                if (_LogonConfig == null)
                {
                    _LogonConfig = new LogonConfig();
                }
                return _LogonConfig;
            }
        }

        /// <summary>
        /// 取平台数据库连接字符串
        /// </summary>
        /// <returns></returns>
        public string GetDbDataBaseConnStr()
        {
            return LogonConfig.GetConnectionStrings(DbDataBaseName);
        }

        /// <summary>
        /// 取内部数据库连接字符串
        /// </summary>
        /// <returns></returns>
        public string GetDbResourcesConnStr()
        {
            return LogonConfig.GetConnectionStrings(DbResourcesName);
        }

        /// <summary>
        /// 取主数据库连接字符串
        /// </summary>
        /// <returns></returns>
        public string GetDbMasterConnStr()
        {
            return LogonConfig.GetConnectionStrings(DbMasterName);
        }

        /// <summary>
        /// 取配置数据库连接字符串
        /// </summary>
        /// <returns></returns>
        public string GetDbConfigConnStr()
        {
            return LogonConfig.GetConnectionStrings(DbConfigName);
        }
    }
}
